package cn.iocoder.yudao.module.written.exam.controller.app.userwrittenexamrecords;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils;
import cn.iocoder.yudao.module.written.exam.controller.admin.userwrittenexamrecords.vo.UserWrittenExamRecordsPageReqVO;
import cn.iocoder.yudao.module.written.exam.controller.app.userwrittenexamrecords.vo.AppUserWrittenExamRecordsRespVO;
import cn.iocoder.yudao.module.written.exam.service.userwrittenexamrecords.UserWrittenExamRecordsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "笔试管理（有关笔试） - 笔试记录")
@RestController
@RequestMapping("/written-exam/user-written-exam-records")
@Validated
public class AppUserWrittenExamRecordsController {

    @Resource
    private UserWrittenExamRecordsService userWrittenExamRecordsService;

    @DeleteMapping("/delete")
    @Operation(summary = "删除笔试记录")
    public CommonResult<Boolean> deleteUserWrittenExamRecords(@RequestParam("id") Long id) {
        userWrittenExamRecordsService.deleteUserWrittenExamRecords(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得笔试记录")
    public CommonResult<AppUserWrittenExamRecordsRespVO> getUserWrittenExamRecords(@RequestParam("id") Long id) {
        return success(userWrittenExamRecordsService.getUserWrittenExamRecordsForApp(id));
    }

    @GetMapping("/page")
    @Operation(summary = "获得笔试记录分页")
    public CommonResult<PageResult<AppUserWrittenExamRecordsRespVO>> getUserWrittenExamRecordsPage(@Valid UserWrittenExamRecordsPageReqVO pageReqVO) {
        pageReqVO.setUserId(WebFrameworkUtils.getLoginUserId());
        return success(userWrittenExamRecordsService.getUserWrittenExamRecordsPageForApp(pageReqVO));
    }

}